#include <iostream>
#include <opencv2/opencv.hpp>
#include <string>

int main()
{
    std::cout << "图像缩放测试程序" << std::endl;

    // 创建测试图像
    cv::Mat orig_img = cv::Mat::zeros(480, 640, CV_8UC3);
    cv::rectangle(orig_img, cv::Point(100, 100), cv::Point(300, 300), cv::Scalar(255, 255, 255), 2);
    cv::putText(orig_img, "Original Image", cv::Point(50, 50), cv::FONT_HERSHEY_SIMPLEX, 1.0, cv::Scalar(255, 255, 255),
                2);

    std::cout << "原始图像尺寸: " << orig_img.cols << "x" << orig_img.rows << std::endl;

    // 模型输入尺寸（从模型信息检查程序获得）
    int model_width = 480;  // 模型输入宽度
    int model_height = 640; // 模型输入高度

    std::cout << "模型输入尺寸: " << model_width << "x" << model_height << std::endl;

    // 创建目标尺寸
    cv::Size target_size(model_width, model_height);
    std::cout << "目标尺寸: " << target_size.width << "x" << target_size.height << std::endl;

    // 缩放图像
    cv::Mat resized_img;
    cv::resize(orig_img, resized_img, target_size);

    std::cout << "缩放后图像尺寸: " << resized_img.cols << "x" << resized_img.rows << std::endl;

    // 计算缩放比例
    float scale_w = (float)target_size.width / orig_img.cols;
    float scale_h = (float)target_size.height / orig_img.rows;

    std::cout << "缩放比例: scale_w=" << scale_w << ", scale_h=" << scale_h << std::endl;

    // 显示图像
    cv::imshow("Original Image", orig_img);
    cv::imshow("Resized Image", resized_img);

    // 在缩放后的图像上添加尺寸信息
    cv::putText(resized_img, "Resized: " + std::to_string(resized_img.cols) + "x" + std::to_string(resized_img.rows),
                cv::Point(10, 30), cv::FONT_HERSHEY_SIMPLEX, 0.7, cv::Scalar(0, 255, 0), 2);

    cv::imshow("Resized with Info", resized_img);

    std::cout << "按任意键退出..." << std::endl;
    cv::waitKey(0);

    return 0;
}